package com.yunxie.novelservice.infra.basic.service.impl;

import com.yunxie.novelservice.infra.basic.entity.Novels;
import com.yunxie.novelservice.infra.basic.mapper.NovelsDao;
import com.yunxie.novelservice.infra.basic.service.NovelsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Novels)表服务实现类
 *
 * @author makejava
 * @since 2025-02-22 21:57:12
 */
@Service("novelsService")
public class NovelsServiceImpl implements NovelsService {
    @Resource
    private NovelsDao novelsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param novelsId 主键
     * @return 实例对象
     */
    @Override
    public Novels queryById(Long novelsId) {
        return this.novelsDao.queryById(novelsId);
    }



    /**
     * 新增数据
     *
     * @param novels 实例对象
     * @return 实例对象
     */
    @Override
    public Novels insert(Novels novels) {
        this.novelsDao.insert(novels);
        return novels;
    }

    /**
     * 修改数据
     *
     * @param novels 实例对象
     * @return 实例对象
     */
    @Override
    public Novels update(Novels novels) {
        this.novelsDao.update(novels);
        return this.queryById(novels.getNovelsId());
    }

    /**
     * 通过主键删除数据
     *
     * @param novelsId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long novelsId) {
        return this.novelsDao.deleteById(novelsId) > 0;
    }

    @Override
    public int countNovels(Novels novels) {

        return  novelsDao.countByCondition(novels);
    }

    @Override
    public List<Novels> queryPage(int start, Integer pageSize) {
        return novelsDao.queryPage(start,pageSize);
    }
}
